<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

    <base href="<%=basePath%>">
    
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
	<link rel="stylesheet" type="text/css" href="css/index.css" />
	
	<title>index Page</title>

</head>
<body>
	<table id="notice"></table>
	
	<div id="notice_tool" style="padding:5px;">
	
		<div style="padding:0 0 0 7px;color:#333;">
			<form id="search">
				<p>
					公告编号：<input type="text" class="textbox" name="noticeIdSearch" style="width:110px">
					公告标题：<input type="text" class="textbox" name="noticeTitleSearch" style="width:110px">
					公告状态：			
					<select id="showStateSearch"  class="textbox" style="width:110px">
						<option ></option>
						<option value="0">待审批</option>
						<option value="1">未通过</option>
						<option value="2">经行中</option>
						<option value="2">已过期</option>
					</select>
					创建时间从：<input type="text" name="date_from" class="easyui-datebox" editable="false" style="width:110px">
					到：<input type="text" name="date_to" class="easyui-datebox" editable="false" style="width:110px">
					<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="notice_tool.search();">查询</a>
				</p>
				
			</form>
				<div style="margin-bottom:5px;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="notice_tool.look();">查看</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-delete-new" plain="true" onclick="notice_tool.remove();">删除</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true"  onclick="notice_tool.reload();">刷新</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-redo" plain="true" onclick="notice_tool.redo();">取消选择</a>	
		</div>
		</div>
	</div>

	<script type="text/javascript" src="<%=path%>/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="<%=path%>/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=path%>/easyui/locale/easyui-lang-zh_CN.js" ></script>
	<script type="text/javascript">
	$(function () {
		$('#notice').datagrid({
			url : 'noticeAction!getNoticeList?isMyNoticeList=1',
			fit : true,
			fitColumns : true,
			striped : true,
			rownumbers : true,
			border : false,
			pagination : true,
			pageSize : 10,
			pageList : [5, 10, 15, 20, 25],
			pageNumber : 1,
			toolbar : '#notice_tool',
			remoteSort:	false,
			columns : [[
				{
					field : 'ck',
					title : '自动编号',
					align:'center',
					width : 100,
					checkbox : true
				},
				{
					field : 'noticeId',
					title : '公告编号',
					align:'center',
					width : 100,
				},
				{
					field : 'noticeTitle',
					title : '公告标题',
					width : 100,
					align:'center',
				},
				{
					field : 'noticeAddUser',
					title : '发布人',
					width : 100,
					align:'center',
				},
				{
					field : 'noticeAddTime',
					title : '发布日期',
					width : 100,
					align:'center',
	  				formatter : function (value, rowData, rowIndex) {
						  if(value != null){
							  var date = new Date(value);
							  return date.getFullYear() + "-" + (date.getMonth()+1)
								+ "-" + date.getDate() +" " + date.getHours() + ":" 
								+ date.getMinutes() + ":" + date.getSeconds();
						  }
					}
				},
				{
					field : 'noticeOverdueTime',
					title : '有效日期',
					width : 100,
					align:'center',
	  				formatter : function (value, rowData, rowIndex) {
						  if(value != null){
							  var date = new Date(value);
							  return date.getFullYear() + "-" + (date.getMonth()+1)
								+ "-" + date.getDate() +" " + date.getHours() + ":" 
								+ date.getMinutes() + ":" + date.getSeconds();
						  }
					}
				},
				{
					field : 'showState',
					title : '公告状态',
					width : 100,
					align:'center',
	  				formatter : function (value, rowData, rowIndex) {
						  if(value == 0){
							  return "<span style='color : blue'>待审批<span>";
						  } else if(value == 1){
							  return "<span style='color : red'>未通过<span>";
						  }else if(value == 2){
							  return "<span style='color : green'>进行中<span>";
						  } else if(value == 3){
							  return "<span style='color : gray'>已过期<span>";
						  }
					}
				}
			]],
			  onDblClickRow: function (index, row) {  
                  var noticeId = row["noticeId"];
                  window.location.href = 'noticeAction!getNoticeByNoticeId?noticeId='+noticeId+'&look=one';
              }
		});
		
		//按钮事件
		notice_tool = {
			look : function (){
				var rows = $('#notice').datagrid('getSelections');
				if (rows.length > 1) {
					$.messager.alert('提示', '查看记录只能选择一条！', 'info');
				} else if (rows.length == 1){
					var noticeId = rows[0].noticeId;
                	window.location.href = 'noticeAction!getNoticeByNoticeId?noticeId='+noticeId+'&look=one';
				} else {
					$.messager.alert('提示', '请选择要查看的记录！', 'info');
				}
				
			},
			//刷新
			reload : function () {
				$('#notice').datagrid('reload');
			},
			//撤销
			redo : function () {
				$('#notice').datagrid('unselectAll');
				$('#search').form('clear');
			},
			//搜索
			search : function () {
				$('#notice').datagrid('load', {
					noticeIdSearch : $.trim($('input[name="noticeIdSearch"]').val()),
					noticeTitleSearch : $.trim($('input[name="noticeTitleSearch"]').val()),
					showStateSearch : jQuery("#showStateSearch").val(),
					date_from : $('input[name="date_from"]').val(),
					date_to : $('input[name="date_to"]').val()
				});
			},
			//删除
			remove : function () {
				var rows = $('#notice').datagrid('getSelections');
				if (rows.length > 0) {
					$.messager.confirm('确定操作', '您正在要删除所选的记录吗？', function (flag) {
						if (flag) {
							var ids = [];
							for (var i = 0; i < rows.length; i ++) {
								ids.push(rows[i].noticeId);
							}
							$.ajax({
								type : 'POST',
								url : 'noticeAction!deleteNotice',
								data : {
									ids : ids.join(',')
								},
								beforeSend : function () {
									$('#notice').datagrid('loading');
								},
								success : function (data) {
									if(data > 0) {
										$('#notice').datagrid('reload');
										$('#notice').datagrid('unselectAll');
										$.messager.show({
											title : '提示',
											msg : data + '个公告被删除成功！',
										});
									} else{
										$('#notice').datagrid('reload');
										$('#notice').datagrid('unselectAll');
										$.messager.alert('删除失败！', '未知错误导致失败，请重试！', 'warning');
									}
								}
							});
						}
					});
				} else {
					$.messager.alert('提示', '请选择要删除的记录！', 'info');
				}
			}
		};
	});
	
	</script>

</body>
</html>
